var ACTION = require("../../base/action");
var utils = require("../../utils/utils");
var ocrGml = require("../../utils/ocrGml");
var aTreasure = new ACTION("开宝箱", {});
var ad = require("../appCommon/fanQieAd");
aTreasure.beforeExec = function () {
  var content = "开宝箱得金币";
  var UIText = utils.existsTextStartsWith(content);
  if (UIText) {
    utils.clickUIText(UIText);
    sleep(utils.getRandom(2, 3, 1000));
    return true;
  }
  var contents = ["开宝箱得金币", "开宝箱"];
  var ocrItem = ocrGml.captureExistOne(contents);
  if (ocrItem) {
    utils.clickOcrItem(ocrItem);
    sleep(utils.getRandom(2, 3, 1000));
    return true;
  }
  return false;
};
aTreasure.exec = function () {
  console.show(true);
  var contentRegExp = /看视频领\d*金币/;
  if (utils.clickTextMatches(contentRegExp)) {
    ad.watchAd();
    sleep(2 * 1000);
    console.hide();
    return;
  }
  var contentRegExp = /看视频再领\d*金币/;
  if (utils.clickTextMatches(contentRegExp)) {
    ad.watchAd();
    sleep(2 * 1000);
    console.hide();
    return;
  }
  var contentRegExp = /看视频领最多\d*金币/;
  if (utils.clickTextMatches(contentRegExp)) {
    ad.watchAd();
    sleep(2 * 1000);
    console.hide();
    return;
  }
  var contentRegExp = /看视频最高再领\d*金币/;
  if (utils.clickTextMatches(contentRegExp)) {
    ad.watchAd();
    sleep(2 * 1000);
    console.hide();
    return;
  }
};
module.exports = aTreasure;
